﻿@{
    ViewBag.Title = "我发布的商品";
    Layout = "~/Views/Shared/_MallLayout.cshtml";
}
<style type="text/css">
    .mescroll {
        position: fixed;
        top: 0;
        bottom: 0;
        height: auto;
        width: 100%;
    }
</style>
<body class="page-order release-order ">
    <div class="mescroll"  id="mescroll">
        <div class="mod-type mod-typeTab mb20">
            <ul>
                <li class="cur" value="-1">
                    全部
                    <i></i>
                </li>
                <li value="0">审核中<i></i></li>
                <li value="1">已发布<i></i></li>
                <li value="2">违规下架<i></i></li>
            </ul>
        </div>
        <div class="mod-order lt-mb">
            <ul id="dataList"></ul>
        </div>
    </div>
    <link href="~/Scripts/mescroll/mescroll.min.css" rel="stylesheet" />
    <script src="~/Scripts/mescroll/mescroll.min.js"></script>
    <script src="~/Scripts/token-common.js"></script>
    <script>
        $(function () {
            var status = -1;
            var mescroll = new MeScroll("mescroll", {
                down: {
                    auto: false,
                    callback: function (mescroll) {
                        mescroll.resetUpScroll(); //下拉刷新的回调,默认重置上拉加载列表为第一页
                    },
                },
                up: {
                    callback: getListData,
                    clearEmptyId: "dataList",
                    isBounce: false,
                    noMoreSize: 3,
                    htmlNodata: '<p class="upwarp-nodata">--没有更多数据了 --</p >',
                    empty: {
                        warpId: "dataList",
                        icon: "",
                        tip: "亲,没有您要找的商品~",

                    },
                    toTop: {
                        //src: "/content/c2c/img/toup.png",
                        //html: "<p>^<br/>顶部<p>",
                        //offset: 500
                    }
                }
            });
            function getListData(page) {
                $.ajax({
                    type: 'post',
                    url: '/BazaarProduct/_Product',
                    data: { page: page.num, size: page.size, status: status },
                    success: function (response) {
                        var paged = $(response).siblings("page");
                        var rows = Number.parseInt(paged.attr("rows"));
                        var total = Number.parseInt(paged.attr("total_result"));
                        mescroll.endBySize(rows, total);
                        if (paged.length == 1) {
                            $("#dataList").append($(response));
                            $('#dataList page').remove();
                        }

                    },
                    error: function (e) {
                        //联网失败的回调,隐藏下拉刷新和上拉加载的状态
                        mescroll.endErr();
                    }
                });
            }
            $(".mod-typeTab li").click(function () {
                var that = $(this);
                that.addClass('cur').siblings().removeClass('cur');
                status = that.val();
                mescroll.resetUpScroll();
                mescroll.hideTopBtn();
            });
            $("#dataList").delegate(".product_share", "click", function (e) {
                var that = $(this);
                var obj = {};
                obj.title ="我在拓垦发布了"+that.attr('data-title');
                obj.desc = that.attr('data-desc');
                obj.img = that.attr('data-imgurl');
                var url = 'http://' + '@Request.Url.Authority' + '/BazaarProduct/Detail?Id=' + that.attr('data-id');
                obj.url = url;
                try {
                    var data = JSON.stringify(obj);
                    if (browser.versions.ios) {
                        window.webkit.messageHandlers.BazaarShare.postMessage(data);
                    } else if (browser.versions.android) {
                        androidfuntion.BazaarShare(data)
                    }
                } catch (e) {
                    layer.msg("暂不支持");

                }
            });
            $("#dataList").delegate(".product_edit", "click", function (e) {
                var id = $(this).attr("data-id");
                try {
                    if (browser.versions.ios) {
                        window.webkit.messageHandlers.BazaarProductEdit.postMessage(id);
                    } else if (browser.versions.android) {
                        androidfuntion.BazaarProductEdit(id)
                    }
                } catch (e) {
                    if (browser.versions.ios || browser.versions.android) {
                        layer.msg("请升级app");
                    }
                    else {
                        layer.msg("请在app内操作");
                    }
                }
            });
            var flag = false;
            $("#dataList").delegate(".product_del", "click", function (e) {
                var id = $(this).attr("data-id");
                 layer.confirm('您确定删除么？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            layer.load(1);
             
                if (flag) return;
                flag = true;
                $.ajax({
                    //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/BazaarProduct/Delete",//url
                    data: { id:id},
                    success: function (result) {
                        layer.closeAll('loading');
                        if (result.result_code == 1000) {
                            layer.msg(result.result_msg);
                            setTimeout(function () {
                                location.reload();
                            }, 1000);
                           
                        }
                        else {
                            layer.msg(result.result_msg);
                        }
                        flag = false;
                    },
                    error: function () {
                        layer.msg("异常！");
                        flag = false;
                    }
                });
        }, function () {

        });
            });
        })
    </script>
</body>
